/*
Special Pythagorean triplet
Problem 9

A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
a2 + b2 = c2

For example, 32 + 42 = 9 + 16 = 25 = 52.

There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.

*/

var solveTask = function () {

    for (var a = 1; a < 1000; a++) {
        for (var b = 1; b < 1000; b++) {
            for (var c = 1; c < 1000; c++) {
                if ((a * a + b * b) === c * c) {
                    if ((a + b + c) === 1000)
                        return a * b * c;
                }
            }
        }
    }

    return -1;
};

var linq = require('linq');
var start = new Date().getTime();

var result = solveTask();

console.log("Result: ", result);

var end = new Date().getTime();
var time = end - start;

console.log("Time: ", time);

require('readline')
    .createInterface(process.stdin, process.stdout)
    .question("Press [Enter] to exit...", function(){
        process.exit();
});